package io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * 实现简易记事本工具
 * 程序启动后在控制台输入的每一行字符串都能顺序写入文件note.txt中
 * 当单独输入exit时程序退出.
 */
public class Test {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("note.txt",true);
//        FileInputStream fis = new FileInputStream("note.txt");
        Scanner scanner = new Scanner(System.in);
        while (true){
            String input = scanner.nextLine();
            if ("exit".equalsIgnoreCase(input)){
                break;
            }
            System.out.println("写入成功");
            byte[] data = input.getBytes(StandardCharsets.UTF_8);
            fos.write(data);
        }
        System.out.println("退出");
        /*data = new byte[1000];
        int len = fis.read(data);
        String name = new String(data,0,len,"utf-8");
        System.out.println(name);
        fis.close();*/
        fos.close();

    }
}
